#ifndef APP_DP_H
#define APP_DP_H

#include "main.h"

#define DP_TYPE_RAW         0x00
#define DP_TYPE_BOOL        0x01
#define DP_TYPE_NUMBER      0x02
#define DP_TYPE_STRING      0x03
#define DP_TYPE_ENUM        0x04
#define DP_TYPE_BITMAP      0x05

#define DP_MEAL_PLAN        1
#define DP_MANUAL_FEED      3
#define DP_FEED_STATE       4
#define DP_BAT              10
#define DP_FAULT            13
#define DP_FEED_REPORT      14

typedef struct {
    unsigned char dpid;
    unsigned char type;
    unsigned short length;

    union {
        const unsigned char *raw;
        const char *string;
        unsigned char boolean;
        int number;
        int enumeration;
        unsigned int bitmap;
    } value;
} dp_obj_t;

typedef enum {
    FEED_STANDBY,   // 喂食待机
    FEED_FEEDING,   // 喂食中
    FEED_DONE,      // 喂食完成
} dp_feed_state_t;

typedef enum {   
    FOOD_JAM,       // 堵粮
    FOOD_SHORTAGES, // 缺粮
    FOOD_RUN_OUT,   // 这是传感器异常，iot平台 故障定义英文名称有猫病
    DESICCANT,      // 这个是电机故障，iot平台 故障定义英文名称有猫病
    BAT_LOW,        // 低电量
} dp_fault_t;

typedef struct {
    dp_feed_state_t state;  // 喂食状态
    unsigned char   fault;  // 故障码
    unsigned char   value;  // app手动喂食份数
    unsigned char   result; // 喂食结果
    unsigned char   bat;    // 电量
} app_dp_value_t;

typedef struct {
    unsigned char all;
} app_dp_notify_t;

extern app_dp_value_t *dp_obj;
extern app_dp_notify_t *dp_notify;
#endif